<?php
/**
 * created by zzy
 * date: 2018/1/26 14:04
 */
namespace App\Eloquent\Ygt;

class WarehouseBillRelation extends DbEloquent{

    protected $table    = 'ygt_warehouse_bill_relation';
    public static $tableFieldList   = [
        ['name'=>'id','title'=>'','value'=>0,'is_must'=>0],
        ['name'=>'company_id','title'=>'登录用户异常','value'=>0,'is_must'=>1],
        ['name'=>'user_id','title'=>'登录用户异常','value'=>0,'is_must'=>1],
        ['name'=>'order_id','title'=>'工单','value'=>0,'is_must'=>1],
        ['name'=>'customer_id','title'=>'客户','value'=>0,'is_must'=>1],
        ['name'=>'pre_number','title'=>'应收单数量','value'=>0,'is_must'=>1],
        ['name'=>'money','title'=>'应收单钱数','value'=>0,'is_must'=>1],
    ];
    public static function edit($data,$pk='')
    {
        $id                 = isset($data['id']) ? intval($data['id']) : 0;
        if($id>0){
            $where          = ['id'=>$id];
            $result         = self::updateOneData($where,$data,$pk);
        } else {
            $result         = self::insertOneData($data,$pk);
        }
        return $result;
    }

    public static function getListByWarehouseBillIdArr($warehousBillIdArr)
    {
        $columns            = 'ygt_warehouse_bill_relation.id,ygt_warehouse_bill_relation.number';
        $columns            .= ',ygt_warehouse_bill_relation.warehouse_bill_id';
        $columns            .= ',ygt_warehouse_bill_relation.price,ygt_warehouse_bill_relation.money';
        $columns            .= ',ygt_warehouse.img_path,ygt_warehouse_bill_relation.money';
        $join               = [
            ['table'=>'ygt_warehouse_bill','field_l'=>'ygt_warehouse_bill.id','field_c'=>'=','field_r'=>'ygt_warehouse_bill_relation.warehouse_bill_id'],
            ['table'=>'ygt_warehouse','field_l'=>'ygt_warehouse.id','field_c'=>'=','field_r'=>'ygt_warehouse_bill_relation.warehouse_id']
        ];
        $where              = [
            'ygt_warehouse_bill_relation.warehouse_bill_id'=>['in',$warehousBillIdArr],
        ];
        $orderby            = ['ygt_warehouse_bill_relation.id','desc'];
        $limit              = $offset = $groupby = '';
        $lists              = self::getList($where,$columns,$limit,$offset,$orderby,$groupby,$join)->toArray();
        return $lists;
    }
}
